package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: HuoXu
 * @Date: 2023/09/18/15:16
 * @Description: 快乐跳跳虎
 */
@RestController("AdminOrderController")
@RequestMapping("/admin/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 获取订单
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> queryOrderDetails(@PathVariable Long id){
        log.info("进入获取订单的窗口");
        OrderVO orderVO=orderService.queryOrders(id);
        return Result.success(orderVO);
    }

    /**
     * 取消订单接口
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("进入管理端取消订单接口,{}",ordersCancelDTO);
        orderService.cancelOrderAdmin(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 获取不同状态的订单
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> countByStatus(){
        log.info("获取不同状态的订单");
        OrderStatisticsVO orderStatisticsVO=orderService.countByStatus();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult=orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 商家接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    public Result receivingOrders(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("商家接单,{}",ordersConfirmDTO);
        orderService.receivingOrders(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 商家拒绝接单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    public Result refusalOfOrders(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("商家拒绝接单,{}",ordersRejectionDTO);
        orderService.refusalOfOrders(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 订单派送
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id){
        log.info("派送接口,{}",id);
        orderService.deliveryOrder(id);
        return Result.success();
    }

    /**
     * 订单完成
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result finishOrder(@PathVariable Long id){
        orderService.finishOrder(id);
        return Result.success();
    }
}
